﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapFGBST(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
   
        public void SaveFGBST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFGBST(dwData, 1);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFGBST(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertFGBST(dwLocal);
            }
            UpdateFGBST(dwLocal);
        }
        public void InsertFGBST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO FGBST(FGMANDANT, FGSA, FGART, FGVAR, FGFARBE, FGGROE, FGAUFM, FGVPEINH, FGZS, FGLO, FGMJJ, FGMM, FGAKTKZ, FGME01, FGME10, FGME11, FGME12, FGME13, FGME19, FGME20, FGME21, FGME24, FGME31, FGME32, FGME33, FGME34, FGME35, FGME36, FGME42, FGME43, FGME46, FGME47, FGME52, FGME53, FGME55, FGME56, FGMEIV, FGME76, FGME79, FGME80, FGME88, FGME89, FGME90, FGME91, FGRE01, FGRE02, FGRE03, FGRE04, FGRE05, FGRE06, FGRE07, FGRE08, FGRE09, FGRE10, FGBSTKMA, FGBSTKME, FGBSTVMA, FGBSTVME, FGBSTA, FGBSTAN, FGBSTMA, FGBSTME, FGINDAT, FGINBST, FGINALT, FGEKPRMA, FGEKPRME, FGEKPRZU, FGVRPR, FGDLABST, FGDLATAG, FGMINBST, FGMAXBST, FGFERTKZ, FGUEBER, FGFILLER, FGAENDZL, FGAENDBEN, FGAENDDAT)"
+ " VALUES (:FGMANDANT, '00',:FGART, :FGVAR, :FGFARBE, :FGGROE, '  ', '   ', '1A', :FGLO, :FGMJJ, :FGMM, 'A', 0, 0, 0, 0, 358, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 358, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 358, 0, 0, 358, 0, 0, 0, 0, 0, 0, 0, 230, '17', 30, 358, 'F', 'N', '                         ', 20, 'YCAV    ', 20140217)";
            or1.Parameters.Add("FGMANDANT", OracleType.NVarChar).Value = dwData["FGMANDANT"].ToString();
            or1.Parameters.Add("FGART", OracleType.NVarChar).Value = dwData["FGART"].ToString();
            or1.Parameters.Add("FGVAR", OracleType.NVarChar).Value = dwData["FGVAR"].ToString();
            or1.Parameters.Add("FGFARBE", OracleType.NVarChar).Value = dwData["FGFARBE"].ToString();
            or1.Parameters.Add("FGGROE", OracleType.NVarChar).Value = dwData["FGGROE"].ToString();
            or1.Parameters.Add("FGLO", OracleType.NVarChar).Value = dwData["FGLO"].ToString();
            or1.Parameters.Add("FGMJJ", OracleType.NVarChar).Value = dwData["FGMJJ"].ToString();
            or1.Parameters.Add("FGMM", OracleType.NVarChar).Value = dwData["FGMM"].ToString();
            Connect2Proxy(or1);
        }
        public DataSet QueryFGBST(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FGBST WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM FGBST "
                        + " WHERE FGMANDANT=:FGMANDANT AND FGMJJ=:FGMJJ AND FGMM=:FGMM AND FGART=:FGART AND FGVAR=:FGVAR AND FGFARBE=:FGFARBE AND FGGROE=:FGGROE"
                        + " AND FGLO=:FGLO";
                    or1.Parameters.Add("FGMANDANT", OracleType.NVarChar).Value = dwData["FGMANDANT"].ToString();
                    or1.Parameters.Add("FGART", OracleType.NVarChar).Value = dwData["FGART"].ToString();
                    or1.Parameters.Add("FGVAR", OracleType.NVarChar).Value = dwData["FGVAR"].ToString();
                    or1.Parameters.Add("FGFARBE", OracleType.NVarChar).Value = dwData["FGFARBE"].ToString();
                    or1.Parameters.Add("FGGROE", OracleType.NVarChar).Value = dwData["FGGROE"].ToString();
                    or1.Parameters.Add("FGLO", OracleType.NVarChar).Value = dwData["FGLO"].ToString();
                    or1.Parameters.Add("FGMJJ", OracleType.NVarChar).Value = dwData["FGMJJ"].ToString();
                    or1.Parameters.Add("FGMM", OracleType.NVarChar).Value = dwData["FGMM"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FGBST";
            Return = Result;
            return Return;
        }
        public void UpdateFGBST(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE FGBST SET "
+ "FGMANDANT=:FGMANDANT,"
+ "FGSA=:FGSA,"
+ "FGART=:FGART,"
+ "FGVAR=:FGVAR,"
+ "FGFARBE=:FGFARBE,"
+ "FGGROE=:FGGROE,"
+ "FGAUFM=:FGAUFM,"
+ "FGVPEINH=:FGVPEINH,"
+ "FGZS=:FGZS,"
+ "FGLO=:FGLO,"
+ "FGMJJ=:FGMJJ,"
+ "FGMM=:FGMM,"
+ "FGAKTKZ=:FGAKTKZ,"
+ "FGME01=:FGME01,"
+ "FGME10=:FGME10,"
+ "FGME11=:FGME11,"
+ "FGME12=:FGME12,"
+ "FGME13=:FGME13,"
+ "FGME19=:FGME19,"
+ "FGME20=:FGME20,"
+ "FGME21=:FGME21,"
+ "FGME24=:FGME24,"
+ "FGME31=:FGME31,"
+ "FGME32=:FGME32,"
+ "FGME33=:FGME33,"
+ "FGME34=:FGME34,"
+ "FGME35=:FGME35,"
+ "FGME36=:FGME36,"
+ "FGME42=:FGME42,"
+ "FGME43=:FGME43,"
+ "FGME46=:FGME46,"
+ "FGME47=:FGME47,"
+ "FGME52=:FGME52,"
+ "FGME53=:FGME53,"
+ "FGME55=:FGME55,"
+ "FGME56=:FGME56,"
+ "FGMEIV=:FGMEIV,"
+ "FGME76=:FGME76,"
+ "FGME79=:FGME79,"
+ "FGME80=:FGME80,"
+ "FGME88=:FGME88,"
+ "FGME89=:FGME89,"
+ "FGME90=:FGME90,"
+ "FGME91=:FGME91,"
+ "FGRE01=:FGRE01,"
+ "FGRE02=:FGRE02,"
+ "FGRE03=:FGRE03,"
+ "FGRE04=:FGRE04,"
+ "FGRE05=:FGRE05,"
+ "FGRE06=:FGRE06,"
+ "FGRE07=:FGRE07,"
+ "FGRE08=:FGRE08,"
+ "FGRE09=:FGRE09,"
+ "FGRE10=:FGRE10,"
+ "FGBSTKMA=:FGBSTKMA,"
+ "FGBSTKME=:FGBSTKME,"
+ "FGBSTVMA=:FGBSTVMA,"
+ "FGBSTVME=:FGBSTVME,"
+ "FGBSTA=:FGBSTA,"
+ "FGBSTAN=:FGBSTAN,"
+ "FGBSTMA=:FGBSTMA,"
+ "FGBSTME=:FGBSTME,"
+ "FGINDAT=:FGINDAT,"
+ "FGINBST=:FGINBST,"
+ "FGINALT=:FGINALT,"
+ "FGEKPRMA=:FGEKPRMA,"
+ "FGEKPRME=:FGEKPRME,"
+ "FGEKPRZU=:FGEKPRZU,"
+ "FGVRPR=:FGVRPR,"
+ "FGDLABST=:FGDLABST,"
+ "FGDLATAG=:FGDLATAG,"
+ "FGMINBST=:FGMINBST,"
+ "FGMAXBST=:FGMAXBST,"
+ "FGFERTKZ=:FGFERTKZ,"
+ "FGUEBER=:FGUEBER,"
+ "FGFILLER=:FGFILLER,"
+ "FGAENDZL=:FGAENDZL,"
+ "FGAENDBEN=:FGAENDBEN,"
+ "FGAENDDAT=:FGAENDDAT "
+ " WHERE FGMANDANT=:FGMANDANT AND FGMJJ=:FGMJJ AND FGMM=:FGMM AND FGART=:FGART AND FGVAR=:FGVAR AND FGFARBE=:FGFARBE AND FGGROE=:FGGROE AND FGLO=:FGLO";
                    or1.Parameters.Add("FGMANDANT", OracleType.NVarChar).Value = dwData["FGMANDANT"].ToString();
                    or1.Parameters.Add("FGSA", OracleType.NVarChar).Value = dwData["FGSA"].ToString();
                    or1.Parameters.Add("FGART", OracleType.NVarChar).Value = dwData["FGART"].ToString();
                    or1.Parameters.Add("FGVAR", OracleType.NVarChar).Value = dwData["FGVAR"].ToString();
                    or1.Parameters.Add("FGFARBE", OracleType.NVarChar).Value = dwData["FGFARBE"].ToString();
                    or1.Parameters.Add("FGGROE", OracleType.NVarChar).Value = dwData["FGGROE"].ToString();
                    or1.Parameters.Add("FGAUFM", OracleType.NVarChar).Value = dwData["FGAUFM"].ToString();
                    or1.Parameters.Add("FGVPEINH", OracleType.NVarChar).Value = dwData["FGVPEINH"].ToString();
                    or1.Parameters.Add("FGZS", OracleType.NVarChar).Value = dwData["FGZS"].ToString();
                    or1.Parameters.Add("FGLO", OracleType.NVarChar).Value = dwData["FGLO"].ToString();
                    or1.Parameters.Add("FGMJJ", OracleType.NVarChar).Value = dwData["FGMJJ"].ToString();
                    or1.Parameters.Add("FGMM", OracleType.NVarChar).Value = dwData["FGMM"].ToString();
                    or1.Parameters.Add("FGAKTKZ", OracleType.NVarChar).Value = dwData["FGAKTKZ"].ToString();
                    or1.Parameters.Add("FGME01", OracleType.NVarChar).Value = dwData["FGME01"].ToString();
                    or1.Parameters.Add("FGME10", OracleType.NVarChar).Value = dwData["FGME10"].ToString();
                    or1.Parameters.Add("FGME11", OracleType.NVarChar).Value = dwData["FGME11"].ToString();
                    or1.Parameters.Add("FGME12", OracleType.NVarChar).Value = dwData["FGME12"].ToString();
                    or1.Parameters.Add("FGME13", OracleType.NVarChar).Value = dwData["FGME13"].ToString();
                    or1.Parameters.Add("FGME19", OracleType.NVarChar).Value = dwData["FGME19"].ToString();
                    or1.Parameters.Add("FGME20", OracleType.NVarChar).Value = dwData["FGME20"].ToString();
                    or1.Parameters.Add("FGME21", OracleType.NVarChar).Value = dwData["FGME21"].ToString();
                    or1.Parameters.Add("FGME24", OracleType.NVarChar).Value = dwData["FGME24"].ToString();
                    or1.Parameters.Add("FGME31", OracleType.NVarChar).Value = dwData["FGME31"].ToString();
                    or1.Parameters.Add("FGME32", OracleType.NVarChar).Value = dwData["FGME32"].ToString();
                    or1.Parameters.Add("FGME33", OracleType.NVarChar).Value = dwData["FGME33"].ToString();
                    or1.Parameters.Add("FGME34", OracleType.NVarChar).Value = dwData["FGME34"].ToString();
                    or1.Parameters.Add("FGME35", OracleType.NVarChar).Value = dwData["FGME35"].ToString();
                    or1.Parameters.Add("FGME36", OracleType.NVarChar).Value = dwData["FGME36"].ToString();
                    or1.Parameters.Add("FGME42", OracleType.NVarChar).Value = dwData["FGME42"].ToString();
                    or1.Parameters.Add("FGME43", OracleType.NVarChar).Value = dwData["FGME43"].ToString();
                    or1.Parameters.Add("FGME46", OracleType.NVarChar).Value = dwData["FGME46"].ToString();
                    or1.Parameters.Add("FGME47", OracleType.NVarChar).Value = dwData["FGME47"].ToString();
                    or1.Parameters.Add("FGME52", OracleType.NVarChar).Value = dwData["FGME52"].ToString();
                    or1.Parameters.Add("FGME53", OracleType.NVarChar).Value = dwData["FGME53"].ToString();
                    or1.Parameters.Add("FGME55", OracleType.NVarChar).Value = dwData["FGME55"].ToString();
                    or1.Parameters.Add("FGME56", OracleType.NVarChar).Value = dwData["FGME56"].ToString();
                    or1.Parameters.Add("FGMEIV", OracleType.NVarChar).Value = dwData["FGMEIV"].ToString();
                    or1.Parameters.Add("FGME76", OracleType.NVarChar).Value = dwData["FGME76"].ToString();
                    or1.Parameters.Add("FGME79", OracleType.NVarChar).Value = dwData["FGME79"].ToString();
                    or1.Parameters.Add("FGME80", OracleType.NVarChar).Value = dwData["FGME80"].ToString();
                    or1.Parameters.Add("FGME88", OracleType.NVarChar).Value = dwData["FGME88"].ToString();
                    or1.Parameters.Add("FGME89", OracleType.NVarChar).Value = dwData["FGME89"].ToString();
                    or1.Parameters.Add("FGME90", OracleType.NVarChar).Value = dwData["FGME90"].ToString();
                    or1.Parameters.Add("FGME91", OracleType.NVarChar).Value = dwData["FGME91"].ToString();
                    or1.Parameters.Add("FGRE01", OracleType.NVarChar).Value = dwData["FGRE01"].ToString();
                    or1.Parameters.Add("FGRE02", OracleType.NVarChar).Value = dwData["FGRE02"].ToString();
                    or1.Parameters.Add("FGRE03", OracleType.NVarChar).Value = dwData["FGRE03"].ToString();
                    or1.Parameters.Add("FGRE04", OracleType.NVarChar).Value = dwData["FGRE04"].ToString();
                    or1.Parameters.Add("FGRE05", OracleType.NVarChar).Value = dwData["FGRE05"].ToString();
                    or1.Parameters.Add("FGRE06", OracleType.NVarChar).Value = dwData["FGRE06"].ToString();
                    or1.Parameters.Add("FGRE07", OracleType.NVarChar).Value = dwData["FGRE07"].ToString();
                    or1.Parameters.Add("FGRE08", OracleType.NVarChar).Value = dwData["FGRE08"].ToString();
                    or1.Parameters.Add("FGRE09", OracleType.NVarChar).Value = dwData["FGRE09"].ToString();
                    or1.Parameters.Add("FGRE10", OracleType.NVarChar).Value = dwData["FGRE10"].ToString();
                    or1.Parameters.Add("FGBSTKMA", OracleType.NVarChar).Value = dwData["FGBSTKMA"].ToString();
                    or1.Parameters.Add("FGBSTKME", OracleType.NVarChar).Value = dwData["FGBSTKME"].ToString();
                    or1.Parameters.Add("FGBSTVMA", OracleType.NVarChar).Value = dwData["FGBSTVMA"].ToString();
                    or1.Parameters.Add("FGBSTVME", OracleType.NVarChar).Value = dwData["FGBSTVME"].ToString();
                    or1.Parameters.Add("FGBSTA", OracleType.NVarChar).Value = dwData["FGBSTA"].ToString();
                    or1.Parameters.Add("FGBSTAN", OracleType.NVarChar).Value = dwData["FGBSTAN"].ToString();
                    or1.Parameters.Add("FGBSTMA", OracleType.NVarChar).Value = dwData["FGBSTMA"].ToString();
                    or1.Parameters.Add("FGBSTME", OracleType.NVarChar).Value = dwData["FGBSTME"].ToString();
                    or1.Parameters.Add("FGINDAT", OracleType.NVarChar).Value = dwData["FGINDAT"].ToString();
                    or1.Parameters.Add("FGINBST", OracleType.NVarChar).Value = dwData["FGINBST"].ToString();
                    or1.Parameters.Add("FGINALT", OracleType.NVarChar).Value = dwData["FGINALT"].ToString();
                    or1.Parameters.Add("FGEKPRMA", OracleType.NVarChar).Value = dwData["FGEKPRMA"].ToString();
                    or1.Parameters.Add("FGEKPRME", OracleType.NVarChar).Value = dwData["FGEKPRME"].ToString();
                    or1.Parameters.Add("FGEKPRZU", OracleType.NVarChar).Value = dwData["FGEKPRZU"].ToString();
                    or1.Parameters.Add("FGVRPR", OracleType.NVarChar).Value = dwData["FGVRPR"].ToString();
                    or1.Parameters.Add("FGDLABST", OracleType.NVarChar).Value = dwData["FGDLABST"].ToString();
                    or1.Parameters.Add("FGDLATAG", OracleType.NVarChar).Value = dwData["FGDLATAG"].ToString();
                    or1.Parameters.Add("FGMINBST", OracleType.NVarChar).Value = dwData["FGMINBST"].ToString();
                    or1.Parameters.Add("FGMAXBST", OracleType.NVarChar).Value = dwData["FGMAXBST"].ToString();
                    or1.Parameters.Add("FGFERTKZ", OracleType.NVarChar).Value = dwData["FGFERTKZ"].ToString();
                    or1.Parameters.Add("FGUEBER", OracleType.NVarChar).Value = dwData["FGUEBER"].ToString();
                    or1.Parameters.Add("FGFILLER", OracleType.NVarChar).Value = dwData["FGFILLER"].ToString();
                    or1.Parameters.Add("FGAENDZL", OracleType.NVarChar).Value = dwData["FGAENDZL"].ToString();
                    or1.Parameters.Add("FGAENDBEN", OracleType.NVarChar).Value = dwData["FGAENDBEN"].ToString();
                    or1.Parameters.Add("FGAENDDAT", OracleType.NVarChar).Value = dwData["FGAENDDAT"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
